﻿using FrameCore.Cryptosystem;
using MemoryPack;
using Server.Business.EnterGame;
using Server.Business.Login;
using Share.Memory;

namespace Server.Module.WebSocket
{
    public static class NetReceiveFunctions
    {
        static Resp GetResp(int _messageId, EMessageMainType messageMainType, EMessageSubType messageSubType, byte[] respData, ECode code)
        {
            return new Resp()
            {
                HeaderMessage = new Header()
                {
                    MainType = messageMainType,
                    SubType = messageSubType,
                    MessageId = _messageId
                },
                Body = respData,
                Code = code
            };
        }

        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="socketId"></param>
        /// <param name="req"></param>
        /// <param name="_messageId"></param>
        public static void Receive_Login_Login(string socketId, LoginReq req, int _messageId)
        {
            Login.GetLoginResp(req, out LoginResp resp, out ECode code);
            
            byte[] respData = MemoryPackSerializer.Serialize(resp);
            Resp data = GetResp(_messageId, EMessageMainType.Login, EMessageSubType.Login, respData, code);
            byte[] sendData = MemoryPackSerializer.Serialize(data);
            
            //ModuleManager.TcpMessageModule.Send(Encryption.DataEncryption(sendData), socketId);
        }

        /// <summary>
        /// 进入游戏
        /// </summary>
        public static void Receive_EnterGame_EnterGame(string socketId, EnterGameReq req, int _messageId)
        {
            EnterGame.Run(socketId, req, out EnterGameResp resp, out ECode code);
            
            byte[] respData = MemoryPackSerializer.Serialize(resp);
            Resp data = GetResp(_messageId, EMessageMainType.EnterGame, EMessageSubType.EnterGame, respData, code);
            byte[] sendData = MemoryPackSerializer.Serialize(data);
            
            //ModuleManager.TcpMessageModule.Send(Encryption.DataEncryption(sendData), socketId);
        }

        /// <summary>
        /// 通信测试
        /// </summary>
        /// <param name="socketId"></param>
        /// <param name="req"></param>
        /// <param name="_messageId"></param>
        public static void Receive_Test1_Test1(string socketId, Test1Req req, int _messageId)
        {
            Test1Resp resp = new Test1Resp() { IsTrue = true};
            
            byte[] respData = MemoryPackSerializer.Serialize(resp);
            Resp data = GetResp(_messageId, EMessageMainType.Test1, EMessageSubType.Test1, respData, ECode.Success);
            byte[] sendData = MemoryPackSerializer.Serialize(data);
            //ModuleManager.TcpMessageModule.Send(Encryption.DataEncryption(sendData), socketId);
        }
        
        /// <summary>
        /// 微信登录
        /// </summary>
        /// <param name="socketId"></param>
        /// <param name="req"></param>
        /// <param name="_messageId"></param>
        public static void Receive_WxLogin_WxLogin(string socketId, WxLoginReq req, int _messageId)
        {
            Login.GetWxLoginResp(req, out WxLoginResp resp, out ECode code);
            
            byte[] respData = MemoryPackSerializer.Serialize(resp);
            Resp data = GetResp(_messageId, EMessageMainType.WxLogin, EMessageSubType.WxLogin, respData, code);
            byte[] sendData = MemoryPackSerializer.Serialize(data);
            //ModuleManager.TcpMessageModule.Send(Encryption.DataEncryption(sendData), socketId);
        }
    }   
}